package trees;

public class RemoveElement {
    public int removeElement(int[] nums, int val) {
        int numLength = nums.length;
        for (int i = 0; i < numLength; i++) {
            if (val == nums[i]) {
                for (int j = i + 1; j < numLength; j++) {
                    nums[j - 1] = nums[j];
                }

                i--;
                numLength--;
            }
        }


        return numLength;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{0, 1, 2, 2, 3, 0, 4, 2};
        int val = 2;
        RemoveElement removeElement = new RemoveElement();
        int result = removeElement.removeElement(nums, val);
        System.out.println(result);
        for (int i = 0; i < result; i++) {
            System.out.print(nums[i] + " ");
        }
    }
}
